home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_09_10 / 9n10091a < prev    next >
Text File  |  1980-01-01  |  1KB  |  81 lines

  1. /*
  2.     listing 4 - lookup.c
  3.  
  4. */
  5.  
  6. #include <stdio.h>
  7. #include "common.h"    /* define structures */
  8.  
  9. FUNC lookup (int type, struct record *position_ptr, 
  10.     struct record *tran_start,     
  11.     int transaction_size, void *user_value)
  12. {
  13.  
  14.   int i;      /* loop control */
  15.   BOOL found=OFF; /* bool value for search lookup */
  16.  
  17.   int integer;      /* hold integer value */
  18.   float floater;  /* hold float value */
  19.  
  20.  
  21.  
  22.   switch (type) {
  23.  
  24.     case INT:
  25.  
  26.     for (i=0, integer = *((int *) position_ptr); 
  27.       i < transaction_size; i++, 
  28.       position_ptr++, integer = *((int *) position_ptr) ) {
  29.  
  30.         if (integer == *( (int *) user_value) ) {  
  31.         found = ON;
  32.         lookup_print(&tran_start[i]);
  33.         }
  34.  
  35.     }
  36.  
  37.     break;
  38.     
  39.     case FLOAT:
  40.  
  41.     for (i=0, floater = *((float *) position_ptr); 
  42.       i < transaction_size; i++, position_ptr++, 
  43.       floater = *((float *) position_ptr) ) {
  44.  
  45.         if (floater == *( (float *) user_value) ) {  
  46.         found = ON;
  47.         lookup_print(&tran_start[i]);
  48.           }
  49.  
  50.        } 
  51.  
  52.     break;
  53.  
  54.     case STRING:
  55.  
  56.     for (i=0; i < transaction_size; i++, position_ptr++) {
  57.  
  58.         if ( !strcmp( position_ptr, (char *) user_value) ) {  
  59.         found = ON;
  60.         lookup_print(&tran_start[i]);
  61.         }
  62.     }
  63.  
  64.         break;
  65.  
  66.  
  67.   };
  68.  
  69.   /* 
  70.     If a comparison was successful, then return SUCCEED, otherwise
  71.     return FAIL.
  72.   */
  73.  
  74.   if (!found) {
  75.     return FAIL;
  76.   } else {
  77.       return SUCCEED;
  78.   }
  79.  
  80. }
  81.